/**
 * Copyright 2018-2020 stylefeng & fengshuonan (https://gitee.com/stylefeng)
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cn.stylefeng.guns.core.constants.factory;

import cn.stylefeng.guns.modular.cms.entity.AdPosition;
import cn.stylefeng.guns.modular.cms.mapper.AdPositionMapper;
import cn.stylefeng.guns.sys.core.constant.factory.ConstantFactory;
import cn.stylefeng.guns.sys.modular.system.entity.Dict;
import cn.stylefeng.guns.sys.modular.system.entity.Menu;
import cn.stylefeng.roses.core.util.SpringContextHolder;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

/**
 * 快捷查询方法
 *
 * @author fengshuonan
 * @date 2017年2月13日 下午10:55:21
 */
@Component
@DependsOn("springContextHolder")
public class ModularConstantFactory implements IModularConstantFactory {
    private AdPositionMapper adPositionMapper = SpringContextHolder.getBean(AdPositionMapper.class);

    public static IModularConstantFactory me() {
        return SpringContextHolder.getBean(ModularConstantFactory.class);
    }

    @Override
    public String getPositionNameById(Integer persionId) {
        AdPosition ap=new AdPosition();
        ap.setApId(persionId);
        QueryWrapper<AdPosition> queryWrapper = new QueryWrapper<>(ap);
        AdPosition adPosition = adPositionMapper.selectOne(queryWrapper);
        if (adPosition != null) {
            return adPosition.getName();
        } else {
            return "--";
        }
    }

    @Override
    public String getUrlNameByUrlType(Integer urlType) {
        return ConstantFactory.me().getDictsByName("URL链接类型",urlType+"");
    }

    @Override
    public String getSexName(String sex) {
        return ConstantFactory.me().getDictsByName("URL链接类型",sex+"");
    }

    @Override
    public String getMemberRoleName(Integer memberRole) {
        return ConstantFactory.me().getDictsByName("会员角色",memberRole+"");
    }

    @Override
    public String getVipGradeName(Integer vipGrade) {
        return ConstantFactory.me().getDictsByName("VIP身份",vipGrade+"");
    }

    @Override
    public String getSourceTypeName(Integer sourceType) {
        return ConstantFactory.me().getDictsByName("平台来源",sourceType+"");
    }

    @Override
    public String getPostCategoryType(Integer type) {
        return ConstantFactory.me().getDictsByName("帖子类型分组",type+"");
    }

}
